
<?php
include_once("db.inc");
$type = $_REQUEST["type"];
$page = $_REQUEST["page"];
$more = $_REQUEST["more"];
$row_number = 12;
$start = $row_number*$page;
if($type==1)
{
$sql = "select * from sanpham join thanhvien on sanpham.doanhnghiep = thanhvien.taikhoan limit $start,$row_number"; 
$sql2 = "select * from sanpham";
}
else
if($type==2)
{
$sql = "select * from sanpham join thanhvien on sanpham.doanhnghiep = thanhvien.taikhoan where doanhnghiep = '$more' limit $start,$row_number"; 
$sql2 = "select * from sanpham join thanhvien on sanpham.doanhnghiep = thanhvien.taikhoan where doanhnghiep = '$more'";
}
else
if($type==4)
{
$sql = "select * from sanpham join thanhvien on sanpham.doanhnghiep = thanhvien.taikhoan where nhomnganh = $more limit $start,$row_number"; 
$sql2 = "select * from sanpham join thanhvien on sanpham.doanhnghiep = thanhvien.taikhoan where nhomnganh = $more";
}
else
if($type==5)
{
$sql = "select * from sanpham join thanhvien on sanpham.doanhnghiep = thanhvien.taikhoan where tensanpham like '%$more%' limit $start,$row_number"; 
$sql2 = "select * from sanpham join thanhvien on sanpham.doanhnghiep = thanhvien.taikhoan where tensanpham like '%$more%'";
}
$result = mysql_query($sql);
$return = "";

$return = $return."<table width=\"100%\">";
for($i=0; $i<4; ++$i)
{
	$return = $return."<tr>";
	for($j=0; $j<3; ++$j)
	{
		$row = mysql_fetch_array($result);
		$MaSanPham = $row["masanpham"];	
		$TenSanPham = $row["tensanpham"];
		$Gia = $row["gia"];
		$hangsanxuat = $row["hangsanxuat"];
		$baohanh = $row["baohanh"];
		$hinhanh = $row["hinhanh"];
		$TenDoanhNghiep = $row["tendoanhnghiep"];
		$DiaChi = $row["diachi"];
		$SoDienThoai = $row["sodienthoai"];
		$data = "Tên sản phẩm&nbsp;&nbsp;&nbsp;<b>$TenSanPham</b><br/>Hãng sản xuất &nbsp;&nbsp;&nbsp;<b>$hangsanxuat</b><br/>													Giá&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>".number_format($Gia,0,',','.')." VND</b><br/>Bảo hành&nbsp;&nbsp;&nbsp;<b>$baohanh tháng</b><br/>Doanh nghiệp phân phối&nbsp;&nbsp;&nbsp;<b>$TenDoanhNghiep</b><br/>Địa chỉ&nbsp;&nbsp;&nbsp;<b>$DiaChi</b><br/>Điện thoại liên hệ&nbsp;&nbsp;&nbsp;<b>$SoDienThoai</b><br/>";
		 //hiển thị ra trình duyệt
		$return = $return."<td onmousemove=\"showinfo('$data')\" onmouseout=\"hideinfo()\" style=\"font-size:14px;color:blue;text-align:center;cursor:pointer;height:170px;width:250px;";			 
		if($i==0 && $j==2)		
			$return = $return."border-right:0px dashed #C0C0C0;border-top:0px dashed #C0C0C0\">";
		else if($i==0 && $j!=2)		
			$return = $return."border-right:1px dashed #C0C0C0;border-top:0px dashed #C0C0C0\">";
		else if($i!=0 && $j==2)		
			$return = $return."border-right:0px dashed #C0C0C0;border-top:1px dashed #C0C0C0\">";
		else	
			$return = $return."border-right:1px dashed #C0C0C0;border-top:1px dashed #C0C0C0\">";
		if($row) 			
			 $return = $return."$TenSanPham<br><img src=\"$hinhanh\"/><br>Giá <b>".number_format($Gia,0,',','.')." VND</b></td>";
		else
			$return = $return."</td>";			 
	}
	$return = $return."</tr>";
}
$return = $return."</table>";
if(mysql_num_rows(mysql_query($sql2))%$row_number == 0)
	$page_number = mysql_num_rows(mysql_query($sql2))/$row_number;
	else $page_number = floor(mysql_num_rows(mysql_query($sql2))/$row_number)+1;
if($page_number > 1)
{
	$return = $return."<p style=\"text-align:center\">";
	if($page != 0)
		$return = $return."<img src=\"images/prev2.jpg\" onclick=\"showSanPham($type,0,'$more')\" style=\"cursor:pointer\">&nbsp;&nbsp;";
		else $return = $return."<img src=\"images/prev2.jpg\" style=\"cursor:pointer\">&nbsp;&nbsp;";
	if($page != 0)
		$return = $return."<img src=\"images/prev.jpg\" onclick=\"showSanPham($type,$page-1,'$more')\" style=\"cursor:pointer\">&nbsp;&nbsp;";
		else $return = $return."<img src=\"images/prev.jpg\" style=\"cursor:pointer\">&nbsp;&nbsp;";
	for($i = 0; $i < $page_number; ++$i)
	{
		if($i == $page)
		$return = $return."<b style=\"cursor:pointer;color:#F00\" class=\"textPage\">".($i+1)."&nbsp;</b>";
		else $return = $return."<b onclick=\"showSanPham($type,$i,'$more')\" style=\"cursor:pointer\" class=\"textPage\">".($i+1)."&nbsp;</b>";
	}
	if($page != $page_number-1)
		$return = $return."<img src=\"images/next.jpg\" onclick=\"showSanPham($type,$page+1,'$more')\" style=\"cursor:pointer\">&nbsp;&nbsp;";
		else $return = $return."<img src=\"images/next.jpg\" style=\"cursor:pointer\">&nbsp;&nbsp;";
	if($page != $page_number-1)
		$return = $return."<img src=\"images/next2.jpg\" onclick=\"showSanPham($type,$page_number-1,'$more')\" style=\"cursor:pointer\"></p>";
		else $return = $return."<img src=\"images/next2.jpg\" style=\"cursor:pointer\"></p>";
}
echo $return;
?>